<html>
  <head>
    <title>Library</title>
    <link href="style.css" rel="stylesheet" type="text/css">
  </head>
  
  <body>

<?php

include_once('conf.php');
include_once('includes/functions.php');

if (isset ($_GET["author"])) {
  $author_path = variable_get('lib_root') . hexToStr ($_GET["author"]);
  $books = getBooks($author_path);
  
  $last_book = '';
  foreach ($books as $book) {
    if (is_dir($book)) {
	  //echo $book . '<br>';
	}
	else {
	  $book_details = pathinfo($book);
    if ($book_details["extension"] == 'zip' && strpos($book_details["filename"],'(html)')) {
      $download = '<a href="download.php?file=' . strToHex($book) . '">html-zip</a>';
      $book_filename = substr($book_details["filename"],0,-6);
    }
    else {
      $download = '<a href="download.php?file=' . strToHex($book) . '">' . $book_details["extension"] . '</a>';
      $book_filename = $book_details["filename"];
    }
	  
	  if ($book_filename == $last_book) {
	    echo ', ' . $download;
	  }
	  elseif ($last_book !== '') {
        echo ')</span><br>
		      <a href="book.php?book=' . strToHex($book) . '" target="body">' . $book_filename 
		   . '</a> <span class = "typelist">(' . $download;
	  }
	  else {
	    echo '<a href="book.php?book=' . strToHex($book) . '" target="body">' . $book_filename 
		   . '</a> <span class = "typelist">(' . $download;
	  }

	}
	$last_book = $book_filename;
  }
  echo ')';
} else {
  echo "Placeholder";
}
  

?>


  </body>
</html>